<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <!-- usage -->
    <div id="app">
        <cpn></cpn>
    </div>

    <!-- template -->
    <template id="cpnT">
        <div>
            <h2>我是组件</h2>
            <cpn2></cpn2>
        </div>
    </template>
    <template id="cpnr">
        <div> 
            <h2>我是组件 2</h2>
            <button @click="showParent">click</button>
        </div>
    </template>

    <!-- script -->
    <script>
        const app = new Vue({
            el: "#app",
            data: {
                name: "tina sl"
            },
            components: {
                cpn: {
                    template: "#cpnT",
                    name: "cpn",
                    data(){
                        return{
                            name: "nameMessage",
                        }
                    },
                    components: {
                        cpn2: {
                            template: '#cpnr',
                            name: 'cpn2',
                            methods: {
                                showParent(){
                                    console.log(this.$parent.name);
                                    console.log(this.$root.name);
                                }
                            }
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>